    $(function(){
     
        $("#dialog").dialog("destroy");

        $("#dialog-select").dialog({autoOpen:false,
                buttons:{"取消":function(){ 
								$(this).dialog("close");
							} ,"确定":function(){
								$("#selected").html("");
								$.each($("#iframe").contents().find(".selectedarea ul li") , function(i ,n){
									//alert($(n).text());
									
									$("#selected").append($(n).text());
									$("#selected").append("<input type='hidden' name='receiver' value='"+$(n).attr("value")+"'>");
								});

								$(this).dialog("close");
							}
						},
                    closeOnEscape:true,
                    hide:"slide",
                    minWidth: 500,
                    width: 500,
                    height: 450,
                    modal:true}
                    );
        $("#sharedselect").click(function(){
               $("#dialog-select").dialog("open");
        });
 
		/* upload file */
		var button = $('.uploadButton'), interval;
		
		new AjaxUpload(button, {
			action: '/xaeduoa/fileUploader/process', 
			name: 'file',
            responseType: 'json',
            data : {
				'upload' : "attachments", 
				'successAction' : "upload",
				'successController' : "articleAjax",
				'errorAction' : "upload",
				'errorController' : "articleAjax"
			}, 

			onSubmit : function(file, ext){
				// change button text, when user selects file
				$('#errors').html('');
				var Uploading = $("#messages");
					Uploading.text('Uploading');
								
				// If you want to allow uploading only 1 file at time,
				// you can disable upload button
				this.disable();
				
				// Uploding -> Uploading. -> Uploading...
				interval = window.setInterval(function(){
					var text = Uploading.text();
					if (text.length < 13){
						Uploading.text(text + '.');					
					} else {
						Uploading.text('Uploading');				
					}
				}, 200);
			},
			onComplete: function(file, response){ 
				
				window.clearInterval(interval);
				 $("#messages").text('');
				// enable upload button
				this.enable();
			 
                if (response.success)
                {	// add file to the list
                     $('#attachmentList').append("<div class='filename'><a href='javascript:'>"+response.message.name + "(" +Math.round(response.message.size/1025)+ "k)"+"</a></div>");
                     $('#attachmentList').append("<input type='hidden' name='attachments' value='"+response.message.id+"'>");
					 
                }else{
                      $('#errors').html("<div class='errors'>"+response.message+"</div>");
                }
			}
		});

	});